#include "RsGisLibClbCalcStandReflSd2010.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClbCalcStandReflSd2010::RsGisLibClbCalcStandReflSd2010(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClbCalcStandReflSd2010();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_DataMaskFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_DataMaskFilePath_clicked()));
	connect(ui->pushButton_SurfaceReflFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_SrefFilePath_clicked()));
	connect(ui->pushButton_SolarIrraFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_SolarIrrFilePath_clicked()));
	connect(ui->pushButton_InciAngleFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_IncAngleFilePath_clicked()));
	connect(ui->pushButton_ExitAngleFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_ExitAngleFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_CalcStandReflSd2010, SIGNAL(clicked()), this, SLOT(on_action_Button_CalcStandReflSd2010_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"Scale Factor - is a float which can be used to scale the output pixel values(e.g., multiple by 1000), set as 1 for no scaling\nBrdf Beta - is the beta parameters in equation 8 in Shepherd and Dymond(2010) for solar elevations between 50 - 70 degrees a value of 1 can be used\nOut Inc Angle - is the incidence angle to which the output image is standardised to(Recommend: 0)\nOut Exit Angle - is the exitance angle to which the output image is standardised to(Recommend: 0)\nGdal Format - string specifying the output image format"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_DataMaskFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\DataMask.tif");
	ui->lineEdit_SurfaceReflFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\SurfaceRefl.tif");
	ui->lineEdit_SolarIrraFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\SolarIrra.tif");
	ui->lineEdit_InciAngleFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\InciAngle.tif");
	ui->lineEdit_ExitAngleFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\ExitAngle.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestCalcStandReflSd2010.tif");
	ui->lineEdit_ScaleFactor->setText("0.0");
	ui->lineEdit_BrdfBeta->setText("0.0");
	ui->lineEdit_OutIncAngle->setText("0.0");
	ui->lineEdit_OutExitAngle->setText("0.0");
	ui->lineEdit_GdalFormat->setText("GTIFF");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_DataMaskFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_DataMaskFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_SrefFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_SurfaceReflFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_SolarIrrFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_SolarIrraFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_IncAngleFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InciAngleFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_ExitAngleFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_ExitAngleFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalcStandReflSd2010::on_action_Button_CalcStandReflSd2010_clicked()
{
	{
		if (ui->lineEdit_DataMaskFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Data Mask File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SurfaceReflFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Surface Refl File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SolarIrraFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Solar Irra File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_InciAngleFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Inci Angle File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ExitAngleFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Exit Angle File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ScaleFactor->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Scale Factor is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_BrdfBeta->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Brdf Beta is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutIncAngle->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Out Inc Angle is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutExitAngle->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Out Exit Angle is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalibration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("CalcStandReflSd2010"));
	AlgParaList << QVariant(QString(ui->lineEdit_DataMaskFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_SurfaceReflFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_SolarIrraFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_InciAngleFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ExitAngleFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(double(ui->lineEdit_ScaleFactor->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_BrdfBeta->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_OutIncAngle->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_OutExitAngle->text().toDouble()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
